package com.example.javapoint.threads.join;

class ThreadJoin extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            try {
                Thread.sleep(300); // 现成休眠300ms
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("当前线程的名称是: " + Thread.currentThread().getName());
            System.out.println(i);
        }
    }
}

public class ThreadJoinExample {
    public static void main(String[] args) {
        ThreadJoin th1 = new ThreadJoin();
        ThreadJoin th2 = new ThreadJoin();
        ThreadJoin th3 = new ThreadJoin();

        th1.start();
        try {
            th1.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        th2.start();
        try {
            th2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        th3.start();
    }
}
